package main

//#link:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/
import (
	. "whoops/leetcode/common"
)

func main() {

}

func removeNthFromEnd(head *ListNode, n int) *ListNode {
	//此处放置倒数第n个节点即头结点，所以新加一个变量
	dummy := &ListNode{Next: head}

	//采用快慢指针
	fast, low := head, dummy
	for n > 0 {
		fast = fast.Next
		n--
	}
	for fast != nil {
		fast = fast.Next
		low = low.Next
	}
	low.Next = low.Next.Next
	return dummy.Next
}
